<?php
require_once('../../auth/auth.php');

	$family_id = $_POST['family_id'];
	
	echo("Debug: family_id is: ". $family_id );

	$apt_number = $_POST['apt_number'];
	$street_address = $_POST['street_address'];
	$city = $_POST['city'];
	$state = $_POST['state'];
	$zipcode = $_POST['zipcode'];
	$num_adults = $_POST['num_adults'];
	$num_children = $_POST['num_children'];
	$other_agency = $_POST['other_agency'];
	$thanksgiving_basket = $_POST['thanksgiving_basket'];
	$food_only = $_POST['food_only'];
	$other = $_POST['other'];
	
	$first_name1 = $_POST['first_name1'];
	$middle_initial1 = $_POST['middle_initial1'];
	$last_name1 = $_POST['last_name1'];
	$gender1 = $_POST['gender1'];
	$date_of_birth1 = $_POST['date_of_birth1'];
	$phone_number1 = $_POST['phone_number1'];
	$last_four_SSN1 = $_POST['last_four_SSN1'];
	$relationship1 = $_POST['relationship1'];
	
	$first_name2 = $_POST['first_name2'];
	$middle_initial2 = $_POST['middle_initial2'];
	$last_name2 = $_POST['last_name2'];
	$gender2 = $_POST['gender2'];
	$date_of_birth2 = $_POST['date_of_birth2'];
	$phone_number2 = $_POST['phone_number2'];
	$last_four_SSN2 = $_POST['last_four_SSN2'];
	$relationship2 = $_POST['relationship2'];
	
	$personalUpdate = !isset($_POST['id']);  	
 	
	if ($personalUpdate){
		 	$user_id = $_SESSION['SESS_USER_ID'];	
	} else {
			$user_id=$_POST['id'];	
	}
	
include 'db_Connect.php';
	

// update Families table	
$updateFamilySql = "UPDATE Families SET apt_number='".$apt_number
			."', street_address='".$street_address
			."', city='".$city
			."', state='".$state
			."', zipcode='".$zipcode
			."', num_adults='".$num_adults
			."', num_children='".$num_children
			."', other_agency='".$other_agency
			."', thanksgiving_basket='".$thanksgiving_basket
			."', food_only='".$food_only
			."' WHERE family_id='".$family_id."'";
$result = mysql_query($updateFamilySql);

if(!$result){
	echo(" <br>Family updated failed!");
}


// update FamilyMembers table
// for Member 1
$member1  = "UPDATE FamilyMembers SET first_name='".$first_name1
			."', middle_initial='".$middle_initial1
			."', last_name='".$last_name
			."', gender='".$gender1
			."', date_of_birth='".$date_of_birth1
			."', phone_number='".$phone_number1
			."', last_four_SSN='".$last_four_SSN1
			."', relationship='".$relationship1
			."' WHERE family_id='".$family_id."'";
			//."' AND contact_1='".'1'."'";
$result1 = mysql_query($member1);

			

if(!$result1){
	echo(" <br> Member 1 updated failed!");
}
			
			
// for Member 2
$member2 = "UPDATE FamilyMembers SET first_name='".$first_name2
			."', middle_initial='".$middle_initial2
			."', last_name='".$last_name2
			."', gender='".$gender2
			."', date_of_birth='".$date_of_birth2
			."', phone_number='".$phone_number2
			."', last_four_SSN='".$last_four_SSN2
			."', relationship='".$relationship2
			."' WHERE family_id='".$family_id
			."' AND contact_2='".'1'
			."'";
$result2 = mysql_query($member2);


if($result2){
	echo("<br>Uppdate succeeded");
	header("Location:../families.php?family_id=".$family_id);
		
} else{
	echo("<br> Member 2 updated failed!");
}

include 'db_Close.php';
?>

